<template>
  <div class="interview_item" v-if="Object.keys(item).length !== 0">
    <div class="content" @click="interviewItemClick">
      <div class="interview_item_title">{{item.title}}</div>
      <div class="interview_item_content">{{item.interview.detail[0].processDesc}}</div>
      <div class="interview_item_detail">
        <div class="post">
          <span>职位:</span>
          <span>{{item.baseInfo.position}}</span>
        </div>
        <div class="firm">
          <span>公司:</span>
          <span>{{item.baseInfo.firm}}</span>
        </div>
      </div>
    </div>
    <div class="cancel" @click="cancelCollect" title="取消收藏">
      <span class="el-icon-remove-outline"></span>
    </div>
  </div>
</template>

<script>
  import {cancelCollect} from "network/collect";

  export default {
    name: "InterviewItem",
    props: {
      item: {
        type: Object,
        default() {
          return {}
        }
      },
      category: {
        type: String,
        request: true
      }
    },
    methods: {
      interviewItemClick() {
        this.$router.push({path: '/detail/' + this.item._id}, onComputed => {}, onAbort => {})
      },
      cancelCollect() {
        this.$confirm('取消收藏此题库, 是否确定?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          const obj = {
            userId: this.$store.state.userInfo.id,
            type: "articles",
            category: this.category,
            collectId: this.item._id
          }
          cancelCollect(obj).then(res => {
            console.log(res)
            if(res.data.code) {
              this.$toast.show('取消收藏成功', 'success', 1000)
              this.$bus.$emit('collectRefresh')
            }
          })
        }).catch(() => {});
      }
    }
  }
</script>

<style scoped>
  .interview_item {
    width: 720px;
    height: 80px;
    margin: 15px auto;
    padding: 10px;
    background-color: #fff;
    box-sizing: border-box;
    border-radius: 10px;
    border: 1px solid #eee;
  }

  .interview_item:hover {
    cursor: pointer;
    box-shadow: 0 0 8px rgba(0,0,0,.1);
  }

  .content {
    position: relative;
    float: left;
    width: 95%;
  }

  .content .interview_item_title {
    width: 450px;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 14px;
    font-weight: 700;
  }

  .content .interview_item_content {
    width: 450px;
    margin-top: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .content .interview_item_detail {
    position: absolute;
    top: 50%;
    left: 480px;
    transform: translate(0, -50%);
    color: #8F9395;
  }

  .cancel {
    position: relative;
    float: right;
    width: 5%;
    height: 60px;
  }

  .cancel .el-icon-remove-outline {
    position: absolute;
    top: 23px;
    left: -1px;
    color: #8F9395;
    font-size: 16px;
  }

  .cancel:hover .el-icon-remove-outline {
    color: #002766;
    cursor: pointer;
  }
</style>firm
